package com.neusoft.neu.fy25g01.n98.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class CommonResult<T> {
    //  200
    // 未达到目的的原因特别多，我们为每一种错误原因指定一个code码
    private Integer code =200;
    private String msg="success";
    private T result;

    public static<T> CommonResult<T> success(){
        return new CommonResult<>(ResultCode.SUCCESS.getCode(),
                ResultCode.SUCCESS.getMsg(),null);
    }
    public static<T> CommonResult<T> success(T result ){
        return new CommonResult<>(ResultCode.SUCCESS.getCode(),
                ResultCode.SUCCESS.getMsg(),result);
    }

    public static <T> CommonResult<T> success(T result, String message) {
        return new CommonResult<>(ResultCode.SUCCESS.getCode(), message, result);
    }

    public static <T> CommonResult<T> failed() {
        return  new CommonResult<>(ResultCode.FAIL.getCode(), ResultCode.FAIL.getMsg(),null ) ;
    }

    public static <T> CommonResult<T> failed(ResultCode resultCode) {
        return  new CommonResult<>(resultCode.getCode(), resultCode.getMsg(),null ) ;
    }

}
